/*    $OpenBSD: ctype.h,v 1.19 2005/12/13 00:35:22 millert Exp $    */
/*    $NetBSD: ctype.h,v 1.14 1994/10/26 00:55:47 cgd Exp $    */

/*
 * Copyright (c) 1989 The Regents of the University of California.
 * All rights reserved.
 *  (c) UNIX System Laboratories, Inc.
 * All or some portions of this file are derived from material licensed
 * to the University of California by American Telephone and Telegraph
 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
 * the permission of UNIX System Laboratories, Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *    @(#)ctype.h    5.3 (Berkeley) 4/3/91
 */

/** @defgroup ctype Ctype
 * @ingroup libc
 */

#ifndef _CTYPE_H_
#define _CTYPE_H_

#include <sys/cdefs.h>
#include <xlocale.h>

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */

#define _CTYPE_U 0x01
#define _CTYPE_L 0x02
#define _CTYPE_D 0x04
#define _CTYPE_S 0x08
#define _CTYPE_P 0x10
#define _CTYPE_C 0x20
#define _CTYPE_X 0x40
#define _CTYPE_B 0x80
#define _CTYPE_R (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_D|_CTYPE_B)
#define _CTYPE_A (_CTYPE_L|_CTYPE_U)

#ifdef __LITEOS__
#define _U _CTYPE_U
#define _L _CTYPE_L
#define _N _CTYPE_D
#define _S _CTYPE_S
#define _P _CTYPE_P
#define _C _CTYPE_C
#define _X _CTYPE_X
#define _B _CTYPE_B
#endif

#ifdef __LITEOS__
typedef unsigned char __ctype_touplow_t;

typedef unsigned short int __uint16_t;
typedef __uint16_t __ctype_mask_t;

#ifndef _ISbit
#define _ISbit(bit) (1 << (bit))
enum
{
    _ISupper = _ISbit (0),    /* UPPERCASE.  */
    _ISlower = _ISbit (1),    /* lowercase.  */
    _ISalpha = _ISbit (2),    /* Alphabetic.  */
    _ISdigit = _ISbit (3),    /* Numeric.  */
    _ISxdigit = _ISbit (4),   /* Hexadecimal numeric.  */
    _ISspace = _ISbit (5),    /* Whitespace.  */
    _ISprint = _ISbit (6),    /* Printing.  */
    _ISgraph = _ISbit (7),    /* Graphical.  */
    _ISblank = _ISbit (8),    /* Blank (usually SPC and TAB).  */
    _IScntrl = _ISbit (9),    /* Control character.  */
    _ISpunct = _ISbit (10),   /* Punctuation.  */
    _ISalnum = _ISbit (11)    /* Alphanumeric.  */
};
#else
#error _ISbit already defined!
#endif
#endif

extern const char    *_ctype_;

#if defined(__GNUC__) || defined(_ANSI_LIBRARY) || defined(lint)
/**
* @ingroup  ctype
*
* @par Description:
* The isalnum() function tests whether c is an alphanumeric character.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The isalnum() function shall return non-zero if c is an alphanumeric character;
* otherwise, it shall return 0.
*
* @par Dependency:
* <ul><li>ctype.h</li></ul>
* @see  isspace | isalpha | isblank | iscntrl | isdigit | isgraph | islower | isprint | ispunct | isupper
* @since Huawei LiteOS V100R001C00
*/
int isalnum(int c);
/**
* @ingroup  ctype
*
* @par Description:
* The isalpha() function tests whether c is an alphabetic character.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The isalpha() function shall return non-zero if c is an alphabetic character;
* otherwise, it shall return 0.
*
* @par Dependency:
* <ul><li>ctype.h</li></ul>
* @see  isspace | isalnum | isblank | iscntrl | isdigit | isgraph | islower | isprint | ispunct | isupper
* @since Huawei LiteOS V100R001C00
*/
int isalpha(int c);
/**
* @ingroup  ctype
*
* @par Description:
* The iscntrl() function tests whether c is a control character.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The iscntrl() function shall return non-zero if c is a control character;
* otherwise, it shall return 0.
*
* @par Dependency:
* <ul><li>ctype.h</li></ul>
* @see  isspace | isalnum | isblank | isalpha | isdigit | isgraph | islower | isprint | ispunct | isupper
* @since Huawei LiteOS V100R001C00
*/
int iscntrl(int c);
/**
* @ingroup  ctype
*
* @par Description:
* The isdigit() function tests whether c is a decimal digit.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The isdigit() function shall return non-zero if c is a decimal digit;
* otherwise, it shall return 0.
*
* @par Dependency:
* <ul><li>ctype.h</li></ul>
* @see  isspace | isalnum | isblank | isalpha | iscntrl | isgraph | islower | isprint | ispunct | isupper
* @since Huawei LiteOS V100R001C00
*/
int isdigit(int c);
/**
* @ingroup  ctype
*
* @par Description:
* The isgraph() function tests whether c is a visible character.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The isgraph() function shall return non-zero if c is a visible character;
* otherwise, it shall return 0.
*
* @par Dependency:
* <ul><li>ctype.h</li></ul>
* @see  isspace | isalnum | isblank | isalpha | iscntrl | isdigit | islower | isprint | ispunct | isupper
* @since Huawei LiteOS V100R001C00
*/
int isgraph(int c);
/**
* @ingroup  ctype
*
* @par Description:
* The islower() function tests whether c is a lowercase letter.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The islower() function shall return non-zero if c is a lowercase letter;
* otherwise, it shall return 0.
*
* @par Dependency:
* <ul><li>ctype.h</li></ul>
* @see  isspace | isalnum | isblank | isalpha | iscntrl | isdigit | isgraph | isprint | ispunct | isupper
* @since Huawei LiteOS V100R001C00
*/
int islower(int c);
/**
* @ingroup  ctype
*
* @par Description:
* The isprint() function tests whether c is a printable character.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The isprint() function shall return non-zero if c is a printable character;
* otherwise, it shall return 0.
*
* @par Dependency:
* <ul><li>ctype.h</li></ul>
* @see  isspace | isalnum | isblank | isalpha | iscntrl | isdigit | isgraph | islower | ispunct | isupper
* @since Huawei LiteOS V100R001C00
*/
int isprint(int c);
/**
* @ingroup  ctype
*
* @par Description:
* The ispunct() function tests whether c is a punctuation character.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The ispunct() function shall return non-zero if c is a punctuation character;
* otherwise, it shall return 0.
*
* @par Dependency:
* <ul><li>ctype.h</li></ul>
* @see  isspace | isalnum | isblank | isalpha | iscntrl | isdigit | isgraph | islower | isprint | isupper
* @since Huawei LiteOS V100R001C00
*/
int ispunct(int c);
/**
* @ingroup  ctype
*
* @par Description:
* The isspace() function tests whether c is a white-space character.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The isspace() function shall return non-zero if c is a white-space character;
* otherwise, it shall return 0.
*
* @par Dependency:
* <ul><li>ctype.h</li></ul>
* @see  isalnum | isalpha | isblank | iscntrl | isdigit | isgraph | islower | isprint | ispunct | isupper
* @since Huawei LiteOS V100R001C00
*/
int isspace(int c);
/**
* @ingroup  ctype
*
* @par Description:
* The isupper() function tests whether c is an uppercase letter.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The isupper() function shall return non-zero if c is an uppercase letter;
* otherwise, it shall return 0.
*
* @par Dependency:
* <ul><li>ctype.h</li></ul>
* @see  isalnum | isalpha | isblank | iscntrl | isdigit | isgraph | islower | isprint | ispunct | isspace
* @since Huawei LiteOS V100R001C00
*/
int isupper(int c);
/**
* @ingroup  ctype
*
* @par Description:
* The isxdigit() function tests whether c is a hexadecimal digit.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The isxdigit() function shall return non-zero if c is a hexadecimal digit;
* otherwise, it shall return 0.
*
* @par Dependency:
* <ul><li>ctype.h</li></ul>
* @see  isalnum | isalpha | isblank | iscntrl | isdigit | isgraph | islower | isprint | ispunct | isspace | isupper
* @since Huawei LiteOS V100R001C00
*/
int isxdigit(int c);
/**
* @ingroup  ctype
*
* @par Description:
* The tolower() function converts uppercase letters to lowercase.
* If c is an uppercase letter, tolower() returns its lowercase
* equivalent. Otherwise, it returns c.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The value returned is that of the converted letter, or c if the
* conversion was not possible.
*
* @par Dependency:
* <ul><li>ctype.h</li></ul>
* @see  isalpha | towlower | towupper
* @since Huawei LiteOS V100R001C00
*/
int tolower(int c);
/**
* @ingroup  ctype
*
* @par Description:
* The toupper() function converts lowercase letters to uppercase.
* If c is a lowercase letter, toupper() returns its uppercase
* equivalent. Otherwise, it returns c.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The value returned is that of the converted letter, or c if the
* conversion was not possible.
*
* @par Dependency:
* <ul><li>ctype.h</li></ul>
* @see  isalpha | towlower | towupper
* @since Huawei LiteOS V100R001C00
*/
int toupper(int c);

#ifndef __LITEOS__
#if __ANDROID_API__ >= 21
int isalnum_l(int, locale_t);
int isalpha_l(int, locale_t);
int isblank_l(int, locale_t);
int iscntrl_l(int, locale_t);
int isdigit_l(int, locale_t);
int isgraph_l(int, locale_t);
int islower_l(int, locale_t);
int isprint_l(int, locale_t);
int ispunct_l(int, locale_t);
int isspace_l(int, locale_t);
int isupper_l(int, locale_t);
int isxdigit_l(int, locale_t);
int tolower_l(int, locale_t);
int toupper_l(int, locale_t);
#endif /* __ANDROID_API__ >= 21 */
#endif

#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE > 200112 \
    || __XPG_VISIBLE > 600
/**
* @ingroup  ctype
*
* @par Description:
* The isblank() function tests whether c is a character of class blank.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The values returned are nonzero if the character c falls
* into the tested class, and zero if not.
*
* @par Dependency:
* <ul><li>ctype.h</li></ul>
* @see  isalnum | isalpha | iscntrl | isdigit | isgraph | islower | isprint | ispunct | isspace | isupper | isxdigit
* @since Huawei LiteOS V100R001C00
*/
int isblank(int c);
#endif

#if __BSD_VISIBLE || __XPG_VISIBLE
/**
* @ingroup  ctype
*
* @par Description:
* The isascii() function tests whether c is a 7-bit US-ASCII character code.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The isascii() function shall return non-zero if c is a 7-bit US-ASCII
* character code between 0 and octal 0177 inclusive; otherwise, it shall return 0.
*
* @par Dependency:
* <ul><li>ctype.h</li></ul>
* @see  toascii
* @since Huawei LiteOS V100R001C00
*/
int isascii(int c);
/**
* @ingroup  ctype
*
* @par Description:
* The toascii() function converts its argument into a 7-bit ASCII character.
*
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @retval #int The toascii() function shall return the value (c &0177).
*
* @par Dependency:
* <ul><li>ctype.h</li></ul>
* @see  isascii
* @since Huawei LiteOS V100R001C00
*/
int toascii(int c);
int _tolower(int);
int _toupper(int);
#endif /* __BSD_VISIBLE || __XPG_VISIBLE */

#endif /* __GNUC__ || _ANSI_LIBRARY || lint */


#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

#endif /* !_CTYPE_H_ */
